excel vba - Apply if statements over ranges of data in VBA -
i have data of varying character length in column aj (anywhere 3 5, or 0 characters). use following piece of code display character length in column ak.
range("ak3:ak15000").formula = "=len(aj3)" i want create new column of data in column al such if character length in ak 5, return in column aj. if character length in ak 4, need return in column aj, 0 (0) in front. if character length 3, need return in column aj, 2 zeros (00) in front. if character length 0 (0), return nothing. following code not work , returns error.
if range("ak3:ak15000").value = 5 range("al3:al15000").formula = "=aj3" elseif range("ak3:ak15000").value = 3 range("al3:al15000").formula = "concatenate(0,0,aj3)" elseif range("ak3:ak15000").value = 4 range("al3:al15000").formula = "concatenate(0,aj3)" end if can please me?
i don't know if possible in version of excel, there may simpler solution.
create column al, give column new format. select column, press ctrl-1, , select custom. in case there type 00000, if it's not there, type 5 0's on field says type.
now add formula copies value column aj al.
if you're not concerned format of column aj, can apply format described above column aj instead.
Comments
Post a Comment