I'm trying to loop through all worksheets in the active workbook, find a word in the first row, and if that word is found, format the entire column. the code I have below only works if on the active worksheet.
What's weird is If I uncomment 'ws.Range("A1") = ws.Name and comment out everything else, it actually loops through the worksheets and changes A1 to the sheet name. so something is off on the iloop maybe?![]()
Sub qtyFormat() Dim ws As Worksheet Dim last_column As Integer For Each ws In ActiveWorkbook.Worksheets last_column = ws.Cells.find("*", [A1], , , xlByColumns, xlPrevious).Column 'On Error Resume Next 'Will continue if an error results 'ws.Range("A1") = ws.Name For iloop = 1 To last_column If InStr(1, ActiveSheet.Cells(1, iloop), "_qty", vbTextCompare) <> 0 Then ws.Columns(iloop).NumberFormat = "#,##0" End If Next iloop '*********************** Next ws End Sub
Thanks











LinkBack URL
About LinkBacks
Register To Reply


Bookmarks