How to return the first cell in a row?

elmnas

Board Regular
Joined
Feb 20, 2015
Messages
206
Hi guys

I use this code but I still dont get the first cell in the same column and row 1



see code below:


Sub Langauge_Combination()


For Each sht In ActiveWorkbook.Worksheets
Set Rng = sht.UsedRange

Set MyRange = Rng
For Each MyCol In MyRange.Columns
For Each MyCell In MyCol.Cells
'MsgBox ("Address: " & MyCell.Address & Chr(10) & "Value: " & MyCell.Value)

If MyCell.Interior.ColorIndex = 23 Then

'MsgBox MyCell.Text








' Put code here
'I tried to use this code but I dont get the first cell on the first row with this

MsgBox "" & MyCell.End(xlUp).Text 'I DONT GET THE FIRST ROW WHY?


End If
Next
Next
Next

End Sub

Could someone help me?
Thank you in advance


 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi, I am not quite sure which first row you need so I have done both . See the Debug.Print statement.

Code:
Sub Langauge_Combination()

    For Each sht In ActiveWorkbook.Worksheets
        Set Rng = sht.UsedRange
        
        Set MyRange = Rng
        For Each MyCol In MyRange.Columns
            For Each MyCell In MyCol.Cells

                 If MyCell.Interior.ColorIndex = 23 Then
        
                     ' Put code here
                     'I tried to use this code but I dont get the first cell on the first row with this
                     Debug.Print "Address1: " & MyCol.Cells(1, 1).Address & " Address2: " & sht.Cells(1, MyCol.Column).Address
                     'Debug.Print "" & MyCell.End(xlUp).Text 'I DONT GET THE FIRST ROW WHY?
                     
                 End If
            Next
        Next
    Next

End Sub
 
Upvote 0
I want the first row in the sheet, (its a list item though. but it's still got only one word in the box)

How do I use it?

as MsgBox I Can't make it work.
 
Upvote 0
Hi, I am not quite sure which first row you need so I have done both . See the Debug.Print statement.

Code:
Sub Langauge_Combination()

    For Each sht In ActiveWorkbook.Worksheets
        Set Rng = sht.UsedRange
        
        Set MyRange = Rng
        For Each MyCol In MyRange.Columns
            For Each MyCell In MyCol.Cells

                 If MyCell.Interior.ColorIndex = 23 Then
        
                     ' Put code here
                     'I tried to use this code but I dont get the first cell on the first row with this
                     Debug.Print "Address1: " & MyCol.Cells(1, 1).Address & " Address2: " & sht.Cells(1, MyCol.Column).Address
                     'Debug.Print "" & MyCell.End(xlUp).Text 'I DONT GET THE FIRST ROW WHY?
                     
                 End If
            Next
        Next
    Next

End Sub

here is a picture

of the example doc

2015_02_26_08_54_24_UCHP_Penta_Translation_Compl.png
 
Upvote 0
Looking at your picture, are you saying that you want to find the text in column 1 of the row that has the blue cell in it.

So from your example, the For Next loops step to where myCell is C3 and you want the text from cell B3.

Try this. It finds the first column of myRange and it knows the row of myCell so it just has to look it up:
Code:
Sub Langauge_Combination()

    For Each sht In ActiveWorkbook.Worksheets
        Set Rng = sht.UsedRange
        
        Set MyRange = Rng
        For Each MyCol In MyRange.Columns
            For Each MyCell In MyCol.Cells

                If MyCell.Interior.ColorIndex = 23 Then
        
                     ' Put code here
                     'I tried to use this code but I dont get the first cell on the first row with this

                    MsgBox "" & sht.Cells(MyCell.Row, MyRange.Columns(1).Column).Text      'I DONT GET THE FIRST ROW WHY?
                     
                 End If
            Next
        Next
    Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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