How to add value to current cell,

elmnas

Board Regular
Joined
Feb 20, 2015
Messages
206
Hello People I have made following code.

The code loop through all cells in a master file column "H" for each value(example H cell contains "Hello") , open a new file check if the value is equal to any of the cells in column "H"; if the value is equal(this case "Hello") take the value same row but instead column "I", copy the number to the master file where it found "Hello", same row but column "I".

Now is my issue instead of replace current value in column "I" in the master file I want my macro to add to current value.

Code:
Sub Use1Work()


    Dim MastShRnG As Range
    Dim SlavRng As Range
    Dim SlaveWb As Workbook
    Dim SlaveWs As Worksheet
    Dim FileName As String
    Dim FolderPath As String
        
    Set MasWb = ActiveWorkbook
    Set MasWbs = Worksheets(1)
    
    x = MasWbs.Range("H" & Rows.Count).End(xlUp).Row
    


    Set MastShRnG = MasWbs.Range("H1:H" & x)
    
    FolderPath = "C:\DATA\"
    
    File = Dir(FolderPath)
    
        While (File <> "")
        
                Set SlaveWb = Workbooks.Open(FolderPath & File)
                Set SlaveWs = SlaveWb.Worksheets(1)
                y = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
                
                Set SlavRng = SlaveWs.Range("H1:H" & y)
                
                For Each cell In SlavRng
                
                             If IsNumeric(cell.Offset(0, 1)) And cell.Value <> "" Then
                                res = Application.Match(cell, MastShRnG, 0)
                                        If Not IsError(res) Then
                                            MasWbs.Cells(res, "I") = cell.Offset(0, 1)
                                            MasWbs.Cells(res, "I").Interior.ColorIndex = 3
                                        Else
                                            x = x + 1
                                            MasWbs.Cells(x, "H") = cell
                                            MasWbs.Cells(x, "I") = cell.Offset(0, 1)
                                            MasWbs.Cells(x, "I").Interior.ColorIndex = 6
                End If
                            End If
                            
                Next cell
                  
                
                
               ' MsgBox MasWbs.Cells(x, "H").Value
  
                
                Workbooks(File).Close SaveChanges:=False
                
                File = Dir
        
        Wend
End Sub

Could someone help me to change my code?

Thank you in advance

best regards
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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