Analog input help

muff03

New Member
Joined
Apr 19, 2011
Messages
3
Hey everyone, just looking for a little bit of help from someone with the knowhow. I've just recently started using VBA, so if this seems pretty straight forward, sorry in advance, but I can't find code that works for me.

I'm using a variable word to tell me the height of water in a tank. I've no problem using the value in excel. What I want to do is have excel look at the height every 5 seconds (located in A1), take a snapshot of the value and copy it into the next cell in column B. So at 'on-time', zero is in B1, 5 seconds later a value is in B2 and so on for roughly 30 minutes.

The code I've come up with works the 5 second delay and the pasting of the value into the appropriate cells, but stops the active cell (A1) from changing at all! Any help would be much appreciated, here's the code I've written:

Sub ctrl()
dim x as integer
for x = 2 to 400
if target = range("A1") Then
if range("A1").value = timevalue("00:0:00") Then
cells(x,2).value = range("A1").value
end if
end if
application.wait now + timevalue("00:00:05")
next x
end sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
sub ctrl()

dim x as integer
For x = 2 to 400
Cells(x,2).value = range("A1").value
Application.wait now+timevalue("00:00:05")
next x

end sub

Not sure where you want to go from there. This will paste the value of A1 into b2, wait 5 seconds, then b3, 5 seconds, b4 (etc...)

What is the next step in whatever you are trying to do? In your last post, what is your target?
 
Last edited:
Upvote 0
sub ctrl()

dim x as integer
For x = 2 to 400
Cells(x,2).value = range("A1").value
Application.wait now+timevalue("00:00:05")
next x

end sub

Not sure where you want to go from there. This will paste the value of A1 into b2, wait 5 seconds, then b3, 5 seconds, b4 (etc...)

What is the next step in whatever you are trying to do?

thanks for the reply, I got it to work about 2 minutes before you got there, a bit different to yours but it works. I'm going to bring the results into MATLAB and do some work on the response curves from the machine there.
 
Upvote 0
the target is an ultrasonic sensor, and I have it scaled to read it's counts (0-32000) in mm instead, so it can see the distance from the water as a height instead.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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