PDA

View Full Version : [SOLVED:] Select Cells Excel VBA



DeanP
01-02-2019, 11:25 AM
Can't believe this is so difficult..... I have an empty column (col A). Column B contains data to cell B526. All I want to do is use VBA to select A2:A526 and fill it with a value.
After hours of research I am no nearer a solution.

Any advise appreciated.

Paul_Hossler
01-02-2019, 12:05 PM
This?




Range("A2:A526").Value = 1234

DeanP
01-02-2019, 12:57 PM
This?




Range("A2:A526").Value = 1234


Hi Paul,

Thanks for your response. I didn't explain properly. I need to be able to always select the same range as cells with data in col B. Col B does not always have the same number of rows containing data.

Paul_Hossler
01-02-2019, 02:36 PM
So for data in B2:B100


Option 1 - A2 = B2, A3 = B3, .... A100 = B100

or

Option 2 - A2:A100 = 1234

?

DeanP
01-02-2019, 03:14 PM
Option 2

Paul_Hossler
01-02-2019, 04:03 PM
This?




Sub Test()

With ActiveSheet
Range(.Range("B2"), .Range("B2").End(xlDown)).Offset(0, -1).Value = 1234
End With

End Sub

DeanP
01-02-2019, 04:15 PM
Thank you for your help! This is what I wanted.

jolivanes
01-02-2019, 05:15 PM
Two more possibilities. One of these (2nd) in case there are empty cells in Column B.

Sub Maybe_A()
Range("A2:A" & Cells(Rows.Count, 2).End(xlUp).Row).Value = 1234
End Sub



Sub Maybe_B()
Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row).SpecialCells(2).Offset(, -1).Value = 1234
End Sub