Hi, below is my code for Excel VBA, I want to know how I can make Range("A2:A4886") dynamic meaning when it calculates istext from another column it f

meetdudhia

New Member
Joined
Jul 8, 2011
Messages
14
Sub function_macro()
Range("A2").Select
ActiveCell.FormulaR1C1 = "=IF(ISTEXT(RC[1]),RC[1],IF(ISTEXT(R[-1]C),R[-1]C,))"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A4886")
Range("A2:A4886").Select
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
ActiveCell.FormulaR1C1 = "Tickt_No"
Range("A2").Select
Columns("A:A").EntireColumn.AutoFit
ActiveCell.FormulaR1C1 = ""
Range("B2:B4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveWindow.SmallScroll Down:=-18
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("A:A").EntireColumn.AutoFit
Range("A1").Select
Application.CutCopyMode = False
ActiveWorkbook.Save

End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try like this

Code:
Sub function_macro()
Dim LR As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
Range("A2:A" & LR).FormulaR1C1 = "=IF(ISTEXT(RC[1]),RC[1],IF(ISTEXT(R[-1]C),R[-1]C,))"
 
Upvote 0
Code:
Dim DataRange As Long 'Counts the number of cells that contain data
    Dim i As Long
    DataRange = Application.WorksheetFunction.CountA(Range("A:A")) - 1
    For i = 1 To DataRange
    
    ...Cells(1 + i, [Your Column Here]) ....Your formula Here...
    Next i

That will dynamically match any data range you define with the data range variable.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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