Column Names with column Nos in Merged Area Displayed but header Name without and after merge cells did not display

Status
Not open for further replies.

SamDsouza

Board Regular
Joined
Apr 16, 2016
Messages
205
Hello

This is in continuation with following thread
.
Somehow i really missed the idea of merged cells in the header row. Approx the code in the above thread helped me to check 35 odd worksheets with what i desired to display header names with column nos. suddenly one Worksheet appeared with header row with merged cells of 4 columns and another sheet with blank cells in header row after each header name.
Case 1 : Found there were merged cells in header Row which gave me its address but next column after the merged cells in header row with header name was not displayed.
Case 2: There were blank cells after each header name in the header row so naturally it did not display the header names of other column because of this syntax
If wks.Cells(RowNumber, x).Value = "" Then Exit For

Can anyone help me to correct the below code with above two issues
VBA Code:
Private Sub CommandButton1_Click()
  Dim wks As Worksheet
  Dim cl As Long, RowNumber As Long, x As Long
  Dim ColValStr As String, msg As String
 
  RowNumber = 3
 
  For Each wks In Worksheets
    ColValStr = ""
    msg = "Name of Sheet: " & wks.Name
   
    cl = wks.Rows(RowNumber).Find(What:="*", _
                        After:=wks.Cells(RowNumber, Columns.Count), _
                        LookAt:=xlPart, _
                        LookIn:=xlFormulas, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False).Column
   
    For x = cl To Columns.Count
      If wks.Cells(RowNumber, x).Value = "" Then Exit For
      ColValStr = ColValStr & vbCrLf & wks.Cells(RowNumber, x).Value & " " & x
    Next x
    MsgBox msg & ColValStr
  Next wks
End Sub
Your guidance will be appreciated
SamD
131
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,833
Messages
6,181,242
Members
453,026
Latest member
cknader

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