Problem finding a cell with certain value

Bonomi

New Member
Joined
Mar 19, 2014
Messages
3
Hi all,

I have to say that I am quite new to excel.
I create a function that returns a cell that contains a value starting at certain cell. The problem is that sometimes it find the correct cell others (for the same value) it doesn't.
Here is my code:

Code:
Public Function FindXValueCell(selectedWorksheet As Worksheet, rowTextCell As Range, xValue As String) As Range
    Dim cell As Range
    
    Set cell = selectedWorksheet.Range(X_VALUES_COLUMN_CONST & ":" & X_VALUES_COLUMN_CONST) _
        .Find(What:=xValue, After:=selectedWorksheet.Cells(rowTextCell.Row, X_VALUES_COLUMN_CONST), _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
        
    Set FindXValueCell = cell
End Function

Any Ideas about what could be wrong?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi
Welcome to the board

Post a sample with data where the function does not find the correct cell, so that we can test.
 
Upvote 0
Hi
Welcome to the board

Post a sample with data where the function does not find the correct cell, so that we can test.


I sorted out about what was wrong and it is not related with this code. Should I delete this post? Sorry about that
 
Upvote 0
Well, I thought I had solved the problem but i didn't! I can't post the whole code but I can post other function that is calling the above one:
Public Sub WriteValue(entityName As String, sectionName As String, xValue As String, yValue As String, valToFill As Currency)
Dim oWB As Workbook
Dim oWS As Worksheet
Dim sectionCell As Range
Dim rowTextCell As Range
Dim xValueCell As Range
Dim yValueCell As Range
Dim tabName As String

'Get tab name
tabName = Mid(sectionName, 1, 1)
tabName = tabName + Mid(sectionName, 3, 2)

'Create new file if it doesn't exist
Set oWB = CopyFileTemplate(sectionName, entityName)
Set oWS = oWB.Sheets(tabName)

Set sectionCell = FindSectionCell(oWS, sectionName)
Set rowTextCell = FindRowTextCell(oWS, sectionCell)
Set xValueCell = FindXValueCell(oWS, rowTextCell, xValue)
Set yValueCell = FindYValueCell(oWS, rowTextCell, yValue)

oWS.Cells(xValueCell.Row, yValueCell.Column).Value = valToFill

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,096
Messages
6,128,809
Members
449,468
Latest member
AGreen17

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