Better way to change the value in a column rather than loop

vonguyenphu

New Member
Joined
May 26, 2019
Messages
29
Hi all,

Can i change the value of columns (>10000 cells) rather than loops which slow my macro.
I need to add "#" to each cell in first column, and in second one i need to add "000" or "00" to increase the number of letter to 5
eg: 567 =>#567 (first column)
20 =>00020(second column)
300 => 00300(second column)
Thks all!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
See if this macro does what you want...
Code:
Sub FixNumberInColumnsAandB()
  With Range("A1", Cells(Rows.Count, "A").End(xlUp))
    .Value = Evaluate("""#""&" & .Address)
    With .Offset(, 1)
      .NumberFormat = "@"
      .Value = Evaluate("IF({1},TEXT(" & .Address & ",""00000""))")
    End With
  End With
End Sub
 
Upvote 0
Fascinating Mr Rothstein, thank you so much! That worked like a magic :D
I searched on google and saw a similar solution with evaluate method to concatenate 2 columns into third column, but i don't know how to solve my problem.
Can you give me more details or reference about how this evaluate method works. I searched on google but still not clear, escpecially how to place quote " inside the parentheses.
 
Upvote 0

Forum statistics

Threads
1,214,865
Messages
6,121,988
Members
449,060
Latest member
mtsheetz

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