To the attention of Rick Rothstein, please for advice

K0st4din

Well-known Member
Joined
Feb 8, 2012
Messages
501
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Platform
  1. Windows
Hello, after a while, I need some help from you.
This macro is written by you, and to this day it helps me a lot.
Every time I open the table and press the button I remember you and your help.


Please for your help, if it is possible to help me change the macro a bit.
Ie to work the same way - to take the information from sheet1 but to transfer the information to a specific sheet, for example in a sheet called "Peaches"

If you have questions, I am at your disposal.
Thank you in advance


Code:
Private Sub CommandButton4_Click()
Dim x As Long, Cell As Range, CellText As String, ws As Worksheet
  Dim Words As Variant, Replacements As Variant
  Const TableSheetName As String = "Sheet1"
  Application.Volatile
  Words = Sheets(TableSheetName).Range("V2", Sheets(TableSheetName).Cells(Rows.Count, "V").End(xlUp))
    Replacements = Sheets(TableSheetName).Range("W2", Sheets(TableSheetName).Cells(Rows.Count, "W").End(xlUp))
    For Each ws In Worksheets 'I think something needs to be changed here to not list all the sheets, but I'm not sure
    lTotalRows = ws.Range("J2", ws.Cells(Rows.Count, "J").End(xlUp)).Rows.Count
    For Each Cell In ws.Range("J2", ws.Cells(Rows.Count, "J").End(xlUp))
    'ProgressBar2.Value = Int(100 * (Cell.Row - 1) / lTotalRows)
    DoEvents
    CellText = ""
      For x = 1 To UBound(Words)
        If InStr(1, Cell.Value, Words(x, 1), vbTextCompare) Then CellText = CellText & "+" & Replacements(x, 1) 'If Cell.Value = Words(X, 1)
      Next
      Cell.Offset(, 6).Value = Mid(CellText, 2) 'PARI P
    Next
  Next
  'ProgressBar2.Value = 100
  'ProgressBar2.Visible = False
End Sub
 
Hello,
I reread a few times what I wrote, but I worry it is not very clear.
The first macro I have shown and written by you - passes through a sheet1 and fills the data in all the others, but it gave me a slight shuffle in the result, that is, it was correct but mixed.
The current macro that changes you works much more accurately, ie 100% is correct.
And for this reason, I ask you if it is possible again with the same macro but fill out all the others except the sheet1.
I do not understand a lot of macros, but something changed, which makes it perfect, :) and the other works, but this one is unique.

P.S. This is just a proposal because I do not know if it is possible to write:After the question "In what worksheet do you want the information to be applied?"
1st - if I write "Peaches" or anybody - to apply only there.
2nd - if I write "All" - to apply to everyone
 
Last edited:
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hello again Rick,
a few days I try to change it, the macro to put the numbers on all the worksheets, but that does not happen.
In the Macro itself, I'll show what I've added, but he does not want to work at all.
It's more than clear that I'm messing around somewhere, but I do not know where !?

Code:
Sub ppppppproba_pari_za_edin_sheet()
Dim X As Long, Z As Long, Answer As String, OutSheet As Worksheet, Parts() As String
  Dim DataFind As Variant, DataReplace As Variant, ResultData As Variant
  Const DataSheet As String = "Sheet1"
  DataFind = Sheets(DataSheet).Range("V2", Sheets(DataSheet).Cells(Rows.Count, "V").End(xlUp))
  DataReplace = Sheets(DataSheet).Range("W2", Sheets(DataSheet).Cells(Rows.Count, "W").End(xlUp))
  On Error GoTo NoSuchSheet
  'Set OutSheet = Sheets(InputBox("IN WITCH SHEET?", vbQuestion)) ' ->>>>> I stop this
  For Each OutSheet In Worksheets - ' ->>>>>>>And put this
  On Error GoTo 0
  ResultData = OutSheet.Range("J2", OutSheet.Cells(Rows.Count, "J").End(xlUp))
  On Error Resume Next
  For X = 1 To UBound(ResultData)
    Parts = Split(ResultData(X, 1), "+")
    For Z = 0 To UBound(Parts)
      Parts(Z) = Application.Lookup(Parts(Z), DataFind, DataReplace)
    Next
    ResultData(X, 1) = Join(Parts, "+")
  Next
  OutSheet.Range("P2").Resize(UBound(ResultData)).NumberFormat = "General"
  OutSheet.Range("P2").Resize(UBound(ResultData)) = ResultData
  On Error GoTo 0
  Exit Sub
NoSuchSheet:
  MsgBox "That sheet name does not exist!", vbCritical
    Next - ' ->>>>>> and this I put
    
End Sub
To my great regret, I just can not handle it.
Please take a look.
Just the new macro works much better than the previous one.
Once you've changed it, it's 100 000% correct.
Thank you in advance!
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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