copying cells from sheet 1 to various other sheets

sbrown64

Board Regular
Joined
Aug 23, 2019
Messages
87
Hi

I have a spreadsheet which has over 1000 lines, all for varying companies. What I would like to do is create an option so when you run it, it will copy the relevant lines to their respective sheet. The code listed below is some I have seen on here, which works to a point. It will run for one company, bit if I press run again it adds the same ones' to sheet 2. The other point is how to make it do if for ALL companies and not just the one? I hope you can help.

Regards

Stephen

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub Copy_Bd()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Dim Lastrowa As Long[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sheets(1).Activate
Lastrow = Cells(Rows.Count, "F").End(xlUp).Row
Lastrowa = Sheets(2).Cells(Rows.Count, "F").End(xlUp).Row + 1[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif] For i = 1 To Lastrow
If Cells(i, 4).Value = "Bd" Then
Rows(i).Copy Destination:=Sheets(2).Rows(Lastrowa)
Lastrowa = Lastrowa + 1
End If
Next
Cells(1, 1).Select
Application.ScreenUpdating = True
End Sub[/FONT]
 
Thanks for the file, could you also please answer the second part part of my question in post#36
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The user doesn't need to delete the data on the company sheets, the macro can do that.
It's more a matter of whether the users are changing or adding anything to company sheets.
 
Upvote 0
the user will add more lines as the info comes in, so that could be an existing company or maybe even a new one, but at the end of each month the bosses would like the inputter be able to print out individual company data and maybe even the full master sheet at times. There may be times that info needs to be corrected if entered incorrectly.

Regards

Stephen
 
Upvote 0
Ok, try this
Code:
Sub sbrown64()
   Dim Cl As Range
   Dim Ky As Variant
   Dim Ws As Worksheet
   Dim UsdRws As Long
   
   Set Ws = Sheets(1)
   UsdRws = Ws.Range("D" & Rows.Count).End(xlUp).Row
   With CreateObject("Scripting.dictionary")
      .CompareMode = vbTextCompare
      For Each Cl In Ws.Range("D5:D" & UsdRws)
         If Cl.Value <> "" Then .item(Trim(Cl.Value)) = Empty
      Next Cl
      For Each Ky In .Keys
         Ws.Range("A4:M" & UsdRws).AutoFilter 4, Ky
         Ws.Range("A4:M" & UsdRws).AutoFilter 13, ""
         If Not Evaluate("isref('" & Left(Ky, 30) & "'!A1)") Then
            Sheets.Add(, Sheets(1)).Name = Left(Ky, 30)
            Ws.Range("A1:A" & UsdRws).SpecialCells(xlVisible).EntireRow.Copy Sheets(Left(Ky, 30)).Range("A1")
            Ws.Range("M5:M" & UsdRws).SpecialCells(xlVisible).Value = Date
         Else
            On Error Resume Next
            Ws.Range("A5:A" & UsdRws).SpecialCells(xlVisible).EntireRow.Copy Sheets(Left(Ky, 30)).Range("D" & Rows.Count).End(xlUp).Offset(1, -3)
            Ws.Range("M5:M" & UsdRws).SpecialCells(xlVisible).Value = Date
            On Error GoTo 0
         End If
      Next Ky
   End With
   Ws.AutoFilterMode = False
End Sub
It will add a date in col M to show that data has been copied & won't be copies again.
I also notice that one of the company names is longer than the max allowed length for a sheet name, so I have capped it 30 characters.
 
Upvote 0
Hi

Thank you for that, i will give it a go and let you know. Thank you for all your help, I will report back as soon as i can, but the wife is now shouting at me to put the BBQ on!

Regards
Stephen
 
Upvote 0
Hi Fluff

Thank you very much for your efforts.

i have entered the code and clicked run and it worked. My question is if an inputter enters a new line of data of the master sheet, how do they update the sheets accordingly? the inputter in question knows next to nothing about computers? just as a thought, how do we check all data has been copied across when there are so many lines? is it a case of an error message would have popped up?

Regards

Stephen
 
Last edited:
Upvote 0
If you select A5, then on the view tab select Freeze panes, then select freeze panes again from the drop down menu. That will keep the top 4 rows visible at all times & you could put a button, or shape in that area & assign the macro to it, then all the user has to do is click the button/shape.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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