SOLVED

Issue with macro copying a range from a random number table into another table

%3CLINGO-SUB%20id%3D%22lingo-sub-2691541%22%20slang%3D%22en-US%22%3EIssue%20with%20macro%20copying%20a%20range%20from%20a%20random%20number%20table%20into%20another%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2691541%22%20slang%3D%22en-US%22%3E%3CP%3EHi.%20Fairly%20new%20to%20Excel%20and%20I%20am%20running%20W10%20with%20MS%20Office%20365%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20table%20(random%20D8%20dice%20rolls)%20that%20generates%20random%20numbers%201-8%20in%20each%20cell%2C%20these%20are%20dice%20rolls%20for%20D8s.%20There%20are%203%20rows%20of%207%20(21%20dice%20in%20total).%20Row%201%20is%20red%20dice%2C%20row%202%20blue%20dice%20and%20row%203%20green%20dice%2C%207%20dice%20of%20each%20colour.%3C%2FP%3E%3CP%3EThese%20dice%20roll%20results%20are%20then%20transferred%20to%20another%20table%26nbsp%3B%20(combat%20rolls)%20but%20only%20filling%20in%20the%20cells%20equal%20to%20how%20many%20dice%20have%20been%20rolled.%20So%20if%20a%20player%20rolls%203%20of%20each%20colour%2C%20only%20the%20first%203%20cells%20of%20each%20coloured%20row%20will%20show%20up.%20The%20remaining%20cells%20left%20blank.%20These%20values%20match%20the%20random%20roll%20values%2C%20which%20is%20great%20and%20what%20I%20wanted.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20we%20know%20when%20something%20is%20done%20in%20the%20sheet%20the%20random%20roll%20table%20(random%20D8%20dice%20rolls)%20will%20update%20and%20copy%20the%20new%20values%20into%20my%20other%20table%20(combat%20rolls).%20I%20don't%20want%20this%20to%20happen.%20So%20I%20have%20created%20a%20new%20table%20and%20a%20Macro%20to%20copy%20and%20paste%20Values%20only%20from%20the%20table%20Combat%20rolls%20to%20a%20new%20table.%20The%20macro%20will%20copy%20and%20paste%20and%20will%20not%20change%20until%20I%20press%20the%20Macro%20button%2C%20even%20if%20the%20random%20roll%20table%20changes.%20This%20is%20what%20I%20wanted.%20However%2C%20values%20do%20not%20match%20what%20is%20being%20copied%20over.%20I%20have%20attached%20an%20image%20of%20the%20sheet%20explaining%20what%20happens%20and%20what%20is%20meant%20to%20happen.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethe%20macro%20to%20copy%20and%20paste%20values%20is%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPrivate%20Sub%20CommandButton1_Click()%3CBR%20%2F%3EApplication.ScreenUpdating%20%3D%20False%3CBR%20%2F%3EDim%20xSheet%20As%20Worksheet%3CBR%20%2F%3ESet%20xSheet%20%3D%20ActiveSheet%3CBR%20%2F%3EIf%20xSheet.Name%20%26lt%3B%26gt%3B%20%22Definitions%22%20And%20xSheet.Name%20%26lt%3B%26gt%3B%20%22fx%22%20And%20xSheet.Name%20%26lt%3B%26gt%3B%20%22Needs%22%20Then%3CBR%20%2F%3ExSheet.Range(%22d12%3Aj14%20%22).Copy%3CBR%20%2F%3ExSheet.Range(%22d22%3Aj24%22).PasteSpecial%20Paste%3A%3DxlValues%2C%20Operation%3A%3DxlNone%2C%20SkipBlanks%3A%3DFalse%2C%20Transpose%3A%3DFalse%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3E%3CBR%20%2F%3EApplication.ScreenUpdating%20%3D%20True%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22spreadsheet3.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306234iCF817C9B96ABBA0C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22spreadsheet3.jpg%22%20alt%3D%22spreadsheet3.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EI%20have%20attached%20the%20spreadsheet%20too%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2691541%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2691767%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20macro%20copying%20a%20range%20from%20a%20random%20number%20table%20into%20another%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2691767%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1139233%22%20target%3D%22_blank%22%3E%40chrissharples%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI'd%20avoid%20using%20formulas%20for%20the%20random%20values%20in%20D6%3AJ8%20-%20running%20the%20macro%20causes%20the%20formulas%20to%20update.%3C%2FP%3E%0A%3CP%3EInstead%2C%20I'd%20add%20a%20button%20to%20roll%20the%20dice.%3C%2FP%3E%0A%3CP%3ESee%20the%20attached%20version.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2692035%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20macro%20copying%20a%20range%20from%20a%20random%20number%20table%20into%20another%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2692035%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20much.%20It%20works%20and%20having%20a%20macro%20for%20the%20random%20dice%20is%20a%20great%20idea.%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20reference%2C%20I%20am%20trying%20to%20re-create%20a%20combat%20mechanism%20from%20a%20board%20game%20(World%20of%20Warcraft%20the%20board%20game)%20into%20excel%20to%20make%20it%20easier%20to%20carry%20out%20the%20combat%20phase.%20I%20have%20still%20lots%20to%20do%20but%20I%20will%20muddle%20on%20through%20it%20utill%20I%20hit%20a%20road%20block.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi. Fairly new to Excel and I am running W10 with MS Office 365

 

I have a table (random D8 dice rolls) that generates random numbers 1-8 in each cell, these are dice rolls for D8s. There are 3 rows of 7 (21 dice in total). Row 1 is red dice, row 2 blue dice and row 3 green dice, 7 dice of each colour.

These dice roll results are then transferred to another table  (combat rolls) but only filling in the cells equal to how many dice have been rolled. So if a player rolls 3 of each colour, only the first 3 cells of each coloured row will show up. The remaining cells left blank. These values match the random roll values, which is great and what I wanted.

 

As we know when something is done in the sheet the random roll table (random D8 dice rolls) will update and copy the new values into my other table (combat rolls). I don't want this to happen. So I have created a new table and a Macro to copy and paste Values only from the table Combat rolls to a new table. The macro will copy and paste and will not change until I press the Macro button, even if the random roll table changes. This is what I wanted. However, values do not match what is being copied over. I have attached an image of the sheet explaining what happens and what is meant to happen. 

 

the macro to copy and paste values is 

 

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim xSheet As Worksheet
Set xSheet = ActiveSheet
If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
xSheet.Range("d12:j14 ").Copy
xSheet.Range("d22:j24").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If

Application.ScreenUpdating = True
End Sub

 

spreadsheet3.jpg

I have attached the spreadsheet too

2 Replies
best response confirmed by chrissharples (New Contributor)
Solution

@chrissharples 

I'd avoid using formulas for the random values in D6:J8 - running the macro causes the formulas to update.

Instead, I'd add a button to roll the dice.

See the attached version.

@Hans Vogelaar 

 

Thank you so much. It works and having a macro for the random dice is a great idea. 

For reference, I am trying to re-create a combat mechanism from a board game (World of Warcraft the board game) into excel to make it easier to carry out the combat phase. I have still lots to do but I will muddle on through it utill I hit a road block.