VBA - searching for elements of an array in active sheet

gavclark86

New Member
Joined
Aug 5, 2013
Messages
2
Hi all, first time posting so apologies if I breach posting etiquette.

I'm trying to write a macro which will find members of an array on a sheet, highlight the column and then change the format of the column, what I have at the moment is:

Dim datearray(1 To 3) As String

datearray(1) = "Date1"
datearray(2) = "Date2"
datearray(3) = "Date3"

For x = LBound(datearray) To UBound(datearray)
Cells.Find(What:=x).Activate
ActiveCell.EntireColumn.Select
Selection.NumberFormat = "m/d/yyyy"
Next x

End Sub

The problem is, when I "F8" my way through the code, it doesn't seem to be finding the members of the array in the sheet. Can anyone help me with this?

I'm a rookie at VBA so apologies if it's something obvious!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Maybe like this

Code:
Dim datearray(1 To 3) As String

datearray(1) = "Date1"
datearray(2) = "Date2"
datearray(3) = "Date3"

For x = LBound(datearray) To UBound(datearray)
Cells.Find(What:=datearray(x), LookIn:=xlValues, lookat:=xlWhole).EntireColumn.NumberFormat = "m/d/yyyy"
Next x

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,075
Members
449,205
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top