copying cells from sheet 1 to various other sheets

sbrown64

Board Regular
Joined
Aug 23, 2019
Messages
83
Hi

Thank you for that, I will go and have a good read of that, just the last point, how do we know all data is copied across? would it tell us if any were missed?
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,835
Office Version
365
Platform
Windows
As long as there is a value in col D then it should get copied.
 

sbrown64

Board Regular
Joined
Aug 23, 2019
Messages
83
Hi

Thank you for all your help, i have now created a button, all seems to be working.

Regards

Stephen
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,835
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

sbrown64

Board Regular
Joined
Aug 23, 2019
Messages
83
Hi again

Just been playing around with the workbook. So we ran a few scenarios and this is what happened. We added a new record with a new company name, we clicked the macro and it worked ok, then we changed the name of the entry to an existing company and re ran the macro, it didn't update the record to anywhere and left the old entry on the new sheet?

We also edited an existing record using Find and replace to change a company name to a new name, it created a new sheet with no records and left the existing sheet in place, it also created a blank sheet called company. The other thing is the macro I have on the master sheet was copied to all the new pages it created, but didn't assign the macro (i.e. didn't want the button copying across).

Regards

Stephen
 

sbrown64

Board Regular
Joined
Aug 23, 2019
Messages
83
Hi also noted that when you run the macro a date is shown in column M and if i try to place a filter on say line 4 and try to filter what is column G, it doesn't work?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,835
Office Version
365
Platform
Windows
The code needs to go in a standard module, not the sheet module.
then we changed the name of the entry to an existing company and re ran the macro, it didn't update the record to anywhere and left the old entry on the new sheet?
That's what I would expect to happen.

If you are editing existing entries & want lines added & deleted accordingly, including deleting sheets, then you will need completely different code.
In which case you will need to start a new thread & explain from the outset, EXACTLY what you need to happen & when.

I cannot replicate a scenario where the shape used to run a macro is copied across to each new sheet.
This will correct some of the other problems
Code:
Sub sbrown64()
   Dim Cl As Range
   Dim Ky As Variant
   Dim Ws As Worksheet
   Dim UsdRws As Long
   
   On Error GoTo Xit
   Application.ScreenUpdating = False
   Set Ws = Sheets(1)
   If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
   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 Xit
         End If
      Next Ky
   End With
   Ws.AutoFilterMode = False
   Exit Sub
Xit:
   Ws.AutoFilterMode = False
   MsgBox "The macro encountered an error" & vbLf & "Error " & Err.Number & " " & Err.Description
End Sub
 

sbrown64

Board Regular
Joined
Aug 23, 2019
Messages
83
Hi

I have just pasted the new code and it works, with regards to editing and deleting lines/tabs i will start a new thread.

Thank you for all your work.

Regards

Stephen
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,835
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

sbrown64

Board Regular
Joined
Aug 23, 2019
Messages
83
Hi again

Just a quick question about this post
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.

Can you point out where that code is? as is may be useful going forward? i.e. is it a case of changing the number?

Regards

Stephen
 

Watch MrExcel Video

Forum statistics

Threads
1,102,676
Messages
5,488,213
Members
407,633
Latest member
varunwalla

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top