excel - In VBA, when I change the format of one column, the adjacent one changes too -
i trying format 2 columns - 1 "general" , 1 "number 0.000," when second 1 formats, changes format of first column "number 0.000" well. if manually select columns , change format works fine. why macro changing format of both columns?
here code snippet:
range("c:c").select selection.numberformat = "general" range("d:d").select selection.numberformat = "0.000"
try avoid using .select
, might cause issues. try:
range("c:c").numberformat = "general" range("d:d").numberformat = "0.000"
that works me.
the reason works if manually select range because when select range, .select
part in macro use selected. avoiding .select
helps ensure no matter cell/range have selected, use explicit range want (in case, range("c:c") , range("d:d")).
Comments
Post a Comment