Forum Discussion
Samarth1508
Mar 17, 2023Copper Contributor
VBA code to change column data
Hi All, I am trying below code to change value of another column but getting error as type mismatch. Sub Update_Data() Dim lr As Long lr = Sheet2.Range("J" & Rows.Count).End(xlUp).Row ...
- Mar 17, 2023
For example:
Sub Import_Data() Dim lr As Long Dim r As Long Dim n As Long lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row For r = 2 To lr If Sheet1.Range("A" & r).Value <> "" Then n = n + 1 Sheet2.Range("A2").Value = Format(Date, "DDMMYYYY") & "_" & Format(n, "000") End If Next r lr = Sheet1.Range("G" & Rows.Count).End(xlUp).Row For r = 2 To lr If Sheet1.Range("G" & r).Value <> "" Then Sheet2.Range("I" & r).Value = _ IIf(Left(Sheet2.Range("J" & r).Value, 4) = "SBIN", "IFT", "NEFT") End If Next r End Sub(I would prefer to use YYYYMMDD as date format since that makes it easier to sort the rows if necessary)
NikolinoDE
Mar 17, 2023Platinum Contributor
excel macro to change values in a column
Sub Update_Data()
Dim lr As Long
Dim i As Long lr = Sheet2.Range(“J” & Rows.Count).End(xlUp).Row For i = 2 To lr
If Not IsEmpty(Sheet2.Cells(i, “J”).Value) Then
Sheet2.Cells(i, “I”).Value = IIf(Left(Sheet2.Cells(i, “J”).Value, 4) = “SBIN”, “IFT”, “NEFT”)
End If
Next i
End Sub
Additional link/info:
Range.Columns property (Excel)