Copy items from sheet1.range(X:X) to next empty cell in range located in Sheet2.

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
As the title says I have a sheet1 and sheet2 where I neeed to check if in range H193:H271 item count is more than 0 and if yes, then copy this value + two offset values to the left, into sheet2 in empty cell in range B11:B30 and C11:C30
and if that range is full then copy those values into empty cell in range of cells next to them in this case(K11:K30 and L11:L30)
This is so what I've got so far:
VBA Code:
Dim Rng As Range, cell As Range, lr As Long
Set Rng = Range("H193:H271")
For Each cell In Rng
    If Not IsEmpty(cell) And cell.Value <> 0 Then
    'GET ELEMENT QTY '
    lr = Sheets("KARTA REALIZACJI").Cells(Rows.Count, "C").End(xlUp).Row
    cell.Copy
        Sheets("Karta Realizacji").Cells(lr + 1, "C").PasteSpecial Paste:=xlPasteValues
     'GET ELEMENT D+E'
    lr = Sheets("KARTA REALIZACJI").Cells(Rows.Count, "C").End(xlUp).Row
    cell.Offset(0, 2).Copy
        Sheets("Karta Realizacji").Cells(lr + 1, "C").PasteSpecial Paste:=xlPasteValues

    

End If
Next cell
Of course this code doesn't work as intended it counts entie B and C column in sheet2 and it also does not combine values D and E together from sheet1.
Please also see attached screenshot for visual reference, and tips and suggestions will be a appreciated.
sheet1.png

sheet2.png
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Please also see attached screenshot for visual reference, and tips and suggestions will be a appreciated.
Try it
VBA Code:
Sub ABC()
    Dim Rng As Range, cell As Range, lr As Long
    Set Rng = Sheet1.Range("H193:H271")
    lr = 10
    For Each cell In Rng
        If Not IsEmpty(cell) And cell.Value <> 0 Then
            lr = lr + 1
            Sheets("Karta Realizacji").Cells(lr, "B").Value = Sheet1.Range("D" & cell.Row).Value & " " & Sheet1.Range("E" & cell.Row).Value
            Sheets("Karta Realizacji").Cells(lr, "C").Value = cell.Value
        End If
    Next cell
End Sub
 
Upvote 0
SO the cod eabovw works perfectly fine however we need to tackle the issue where if tehre are more thna 20 itrmd "imported" I need them to go to different range, I tried this code, but it deosnt work properly.
So every item above 20 should go to coulmn K and L and every item above that 40 should go to collumn T and U.
VBA Code:
Sub export_click()
    Dim Rng As Range, cell As Range, lr As Long
    Set Rng = ActiveSheet.Range("H193:H271")
    lr = 10
    For Each cell In Rng
        If Not IsEmpty(cell) And cell.Value <> 0 Then
            lr = lr + 1
            If lr <= 20 Then
            Sheets("KARTA REALIZACJI").Cells(lr, "B").Value = ActiveSheet.Range("D" & cell.Row).Value & " " & ActiveSheet.Range("E" & cell.Row).Value
            Sheets("KARTA REALIZACJI").Cells(lr, "C").Value = cell.Value
            ElseIf lr > 20 And lr < 41 Then
            Sheets("KARTA REALIZACJI").Cells(lr, "K").Value = ActiveSheet.Range("D" & cell.Row).Value & " " & ActiveSheet.Range("E" & cell.Row).Value
            Sheets("KARTA REALIZACJI").Cells(lr, "L").Value = cell.Value
            ElseIf lr > 40 And lr < 61 Then
            Sheets("KARTA REALIZACJI").Cells(lr, "T").Value = ActiveSheet.Range("D" & cell.Row).Value & " " & ActiveSheet.Range("E" & cell.Row).Value
            Sheets("KARTA REALIZACJI").Cells(lr, "U").Value = cell.Value
            End If
        End If
    Next cell
End Sub

The results:
1655453489720.png
 
Upvote 0
VBA Code:
Sub export_click()
    Dim Rng As Range, cell As Range, lr As Long, i&, J&
    Set Rng = Arkusz2.Range("H193:H271")
    lr = 10: J = 2
    For Each cell In Rng
        If Not IsEmpty(cell) And cell.Value <> 0 Then
            lr = lr + 1: i = i + 1
            If i Mod 21 <> 0 Then
                Sheets("KARTA REALIZACJI").Cells(lr, J).Value = ActiveSheet.Range("D" & cell.Row).Value & " " & ActiveSheet.Range("E" & cell.Row).Value
                Sheets("KARTA REALIZACJI").Cells(lr, J + 1).Value = cell.Value
            Else
                J = J + 9
                lr = 10
            End If
        End If
    Next cell
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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