Merge code into one

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I use these two codes to import or export data into my sheet, however, how can I merge them?

In this code,...

VBA Code:
    For Each c In Wks.Range("A7:A" & lRow)
        If Not c.Comment Is Nothing Then
            With BkUp.Sheets(1).Cells(c.Row - 6, "S")
                .Value = .Value & COMMENT_DELIMITER & c.Comment.Text
            End With
        End If
    Next c

    For Each c In Wks.Range("S7:S" & lRow)
        If Not c.Comment Is Nothing Then
            With BkUp.Sheets(1).Cells(c.Row - 6, "S")
                .Value = .Value & COMMENT_DELIMITER & c.Comment.Text
            End With
        End If
    Next c



This code difference is ...

For Each c In .Columns(1).Cells
vs
For Each c In .Columns(19).Cells


and the first code does not have .Name = Wks.Cells(c.Row, "A").Value & Format(Wks.Cells(c.Row, "O").Value * 100, "00000000000")


VBA Code:
                If UBound(Data, 2) >= 19 Then
                    For Each c In .Columns(1).Cells
                        If InStr(1, c.Value, COMMENT_DELIMITER) Then
                            v = Split(c.Value, COMMENT_DELIMITER)
                            c.Value = v(0)
                            c.AddComment Text:=v(1)
                            c.Comment.Shape.TextFrame.AutoSize = True
                            With Wks.Shapes.AddShape(msoShapeRightTriangle, c.Left, c.Top, 7, 7)
                                .Rotation = 90
                                .Fill.ForeColor.RGB = RGB(255, 0, 0)
                                .Fill.Solid
                                .Line.Visible = msoFalse
                                .OnAction = "ImageTag"
                            End With
                        End If
                    Next c
                End If

                If UBound(Data, 2) >= 19 Then
                   For Each c In .Columns(19).Cells
                        If InStr(1, c.Value, COMMENT_DELIMITER) Then
                            v = Split(c.Value, COMMENT_DELIMITER)
                            c.Value = v(0)
                            c.AddComment Text:=v(1)
                            c.Comment.Shape.TextFrame.AutoSize = True
                            With Wks.Shapes.AddShape(msoShapeRightTriangle, c.Left, c.Top, 7, 7)
                                .Name = Wks.Cells(c.Row, "A").Value & Format(Wks.Cells(c.Row, "O").Value * 100, "00000000000")
                                .Rotation = 90
                                .Fill.ForeColor.RGB = RGB(255, 0, 0)
                                .Fill.Solid
                                .Line.Visible = msoFalse
                                .OnAction = "Remarks"
                            End With
                        End If
                    Next c
                End If
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi,
try the Union method to combine the Ranges & see if this will do what you want

VBA Code:
For Each c In Union(Wks.Range("A7:A" & lRow), Wks.Range("S7:S" & lRow)).Cells
        If Not c.Comment Is Nothing Then
            With BkUp.Sheets(1).Cells(c.Row - 6, "S")
                .Value = .Value & COMMENT_DELIMITER & c.Comment.Text
            End With
        End If
    Next c

Dave
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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