473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Excel VBA Macro Question

I have a spreadsheet with cells that use randbetween(). At the bottom of each column there is a sum() cell for these cells. I made a macro that refreshes the values until a column's total is within a certain number range. Each time a sum cell is true to this criteria it should "paste special" the column's values to a range of cells in a blank table corresponding to it. It doesn't seem to work though. It never paste's anything and contiues to generate random values even though I see it hitting the correct numbers.

Here's the code:

Sub GEN()
Do
Calculate
If ([B8] < 40) And ([B8] > 38) Then
Range("B4:B9").Select
Selection.Copy
ActiveSheet.Range("B15:B20").PasteSpecial Paste:=xlPasteValues
End If
Loop Until ([B8] < 40) And ([B8] > 38)


Do
Calculate
If ([C8] < 40) And ([C8] > 38) Then
Range("C4:C9").Select
Selection.Copy
Worksheets(1).Range("C15:C20").PasteSpecial Paste:=xlPasteValues
End If
Loop Until ([C8] < 40) And ([C8] > 38)


Do
Calculate
If ([D8] < 40) And ([D8] > 38) Then
Range("D4:D9").Select
Selection.Copy
ActiveSheet.Range("D15:D20").PasteSpecial Paste:=xlPasteValues
End If
Loop Until ([D8] < 40) And ([D8] > 38)


Do
Calculate
If ([E8] < 40) And ([E8] > 38) Then
Range("E4:E9").Select
Selection.Copy
ActiveSheet.Range("E15:E:20").PasteSpecial Paste:=xlPasteValues
End If
Loop Until ([E8] < 40) And ([E8] > 38)
End Sub
Oct 9 '07 #1
3 2320
kadghar
1,295 Expert 1GB
...

Here's the code:

Sub GEN()
Do
Calculate
If ([B8] < 40) And ([B8] > 38) Then
Range("B4:B9").Select
Selection.Copy
ActiveSheet.Range("B15:B20").PasteSpecial Paste:=xlPasteValues
End If
Loop Until ([B8] < 40) And ([B8] > 38)
...
I'll make some changes in the first one, try it with the rest

Expand|Select|Wrap|Line Numbers
  1. Do
  2.     Calculate
  3.     If cells(2,8) < 40 And cells(2,8) > 38 Then
  4.         Range("B4:B9").copy
  5.         cells(2,15).pastespecial -4163
  6.         exit do
  7.     End If
  8. Loop
Oct 9 '07 #2
Thanks for the quick response. When I looked over my code later with a fresh head I realized that I inputted the wrong sum cell location, so my code works. When I ran yours it kept generating rands. Are you sure that the cells() function works like that? I tried it with .value but that didn't work either.
Oct 10 '07 #3
kadghar
1,295 Expert 1GB
Are you sure that the cells() function works like that?
Actually im sure they dont work like that i wrote columns first, then rows, it should be rows then columns.

For B8 its cells(8,2)

my apologies :$
Oct 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
1
by: Steven Stewart | last post by:
I have a user who has been using Excel for a while to keep statistics and print reports. She finds using it cumbersome because of long formulas and a lot of copying and pasting. I have designed...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
0
by: Bodmonkey | last post by:
Hi Experts, I'm both very new to Python and to VBA, so my question may well be a simple one but i'm tearing my hair out Basically i get a different excel files produced in any number after...
4
by: michael.pearmain | last post by:
Hi Experts, Looking for a very quick bit on of advice on how to make some python code run. I'm a newbie to both VBA and Python, so i apologise if this is very easy but i'm about to tear my hair...
2
by: Senthil | last post by:
Hi All I need to create an Excel report and create a command button and have to run a macro on the click event that will print all the pages in the Excel workbook. I am able to create the report...
7
by: Holger Fitschen | last post by:
Hi to all, I want to use the Excel solver in a VB.Net project. The macro Sub Makro1Solver() Application.Run "Solver.xla!Auto_Open" SolverReset Worksheets(1).Select...
3
by: akristensen | last post by:
I am new to this site, so be patient if I do not ask the question correctly. Current Target Platform: Browser: MS IE, script language: Javascript (will use VBScript, but JS is preferred), External...
7
by: bobh | last post by:
Hi, I have this code in the groupheader_print section of an AccessXP report. What is the code to 'Bold' the text288 cell. thanks bobh. 'this is the rpting category header wks.Cells(row, 1) =...
1
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.