|
 |
|
|
|
|
 |
07-25-2006, 12:46 AM
|
#1 (permalink)
|
|
Red Belt, but BlackBeltLastYear
| Location:
daly city/San francisco |
Status:
|
|
advanced MS excel macro/visual basic question
Does anyone know how to obtain a value from a cell? let's say you want to extract the value/string on cell B4. Do you know how to do that? I have a VBA book, and I can't find it (possibly b/c i don't know what the function is called so i dont' know how to look it up)
i need it for work, cuz we only have one head software engineer and he's busy working on our new robots at work.
__________________
"The president now defines progress as moving forward through time" -- Jon Stewart
|
| |
|
07-25-2006, 10:37 AM
|
#2 (permalink)
|
|
Banned
Status:
|
|
umm are you trying to copy the string in b4 and paste it on another excel work sheet? what are you trying to do here?
|
| |
|
07-25-2006, 12:55 PM
|
#3 (permalink)
|
|
Red Belt, but BlackBeltLastYear
| Location:
daly city/San francisco |
Status:
|
|
Lets say in B4 it says 104445. I want ot make a macro, which saves the excel file in a folder with the same value/string within a cell (i.e. B4), so if the macro works, it should save the current file as 104445.xls . A lot of coworkers are computer illiterate (they're old), and don't know how to save in the right directory
in general, my lab is disorganized. the label maker we have is just barely "sufficient". the label maker is unnencessaril difficult. it takes like 3 steps. my current (and done) method takes one. this seems to not be simple enough since the computer illiterates save the final file in the wrong directory. i want to make the save function automated. Our lab is a science lab, and it just takes too much time and energy making somethign so trivial like labels.
my current desperate solution is, when u click "save" it has a popup window and asks you to type the file name, and the macro will save using that file name u just typed into the right directory, but this is error prone cuz some ppl might type the wrong number there inadvertently, and save as the wrong file name.
__________________
"The president now defines progress as moving forward through time" -- Jon Stewart
Last edited by BlackBeltNow : 07-25-2006 at 01:02 PM.
|
| |
|
07-25-2006, 04:45 PM
|
#4 (permalink)
|
|
Banned
Status:
|
|
Quote:
Sub name()
Dim fname As String
Range("b6").Activate
fname = ActiveCell
ActiveWorkbook.SaveAs fname
End Sub
|
alright this worked for me, tell me if you have any problems.
* for some reason when i try to run it via the module in the vba screen it returns a compile error. but when i create a button in the workbook it works..
|
| |
|
07-25-2006, 05:33 PM
|
#5 (permalink)
|
|
Red Belt, but BlackBeltLastYear
| Location:
daly city/San francisco |
Status:
|
|
so waht does this function do? if called, it stores the data of B6 (err b4?) into string "fname"? so i just gotta use the value of "fname" in later code?
__________________
"The president now defines progress as moving forward through time" -- Jon Stewart
|
| |
|
07-25-2006, 06:02 PM
|
#6 (permalink)
|
|
Banned
Status:
|
|
Quote:
|
Originally Posted by BlackBeltNow
so waht does this function do? if called, it stores the data of B6 (err b4?) into string "fname"? so i just gotta use the value of "fname" in later code?
|
Quote:
Sub name()
Range("b6").Activate
ActiveWorkbook.SaveAs Activecell
End Sub
|
god damnit i can't believe i did that... but try the one up there without the redundant code.
all that code does is when assigned to either a Ctrl + (?), or a button it Saves as the value in cell b6.
|
| |
|
07-25-2006, 06:08 PM
|
#7 (permalink)
|
|
Banned
Status:
|
|
oh you know what i misread what you were asking...
you want something to recognize a value in a cell while saving it in the coinciding directory?
|
| |
|
07-25-2006, 10:32 PM
|
#8 (permalink)
|
|
Red Belt, but BlackBeltLastYear
| Location:
daly city/San francisco |
Status:
|
|
Quote:
|
Originally Posted by childrenofbodom
oh you know what i misread what you were asking...
you want something to recognize a value in a cell while saving it in the coinciding directory?
|
well, i just need any way of getting a cel string to be a file name. extracting the cell to a variable is good enough, cuz i know how to make a macro save a fiel w/ the value of a variable anyway, so getting a cell --> string is good enough for me.
i only write VBA by modification, not from scratch, so don't correc the following typos. i just need anyway to save the data of B4 into a variable/string. so, if u teach me how to store B4 into a string fname, i can just add the line downstream of that
Save: "C:\MyData\" "&fname" ".xls"
yes i know what ampersand may stand for another type of variable, a number or something, but dont' correct me. i only write VBA's w/ a refernece book since my major was not computer science. i'll figure it out. all i need to know is how to get a cel's info to a variable.
__________________
"The president now defines progress as moving forward through time" -- Jon Stewart
|
| |
|
07-25-2006, 10:40 PM
|
#9 (permalink)
|
|
Banned
Status:
|
|
Tell you what.. I will check at work tommarrow for otther ways too. I have to use that bloated POS all day.
|
| |
|
07-26-2006, 12:58 PM
|
#10 (permalink)
|
|
Banned
Status:
|
|
Quote:
|
Originally Posted by BlackBeltNow
well, i just need any way of getting a cel string to be a file name. extracting the cell to a variable is good enough, cuz i know how to make a macro save a fiel w/ the value of a variable anyway, so getting a cell --> string is good enough for me.
i only write VBA by modification, not from scratch, so don't correc the following typos. i just need anyway to save the data of B4 into a variable/string. so, if u teach me how to store B4 into a string fname, i can just add the line downstream of that
Save: "C:\MyData\" "&fname" ".xls"
yes i know what ampersand may stand for another type of variable, a number or something, but dont' correct me. i only write VBA's w/ a refernece book since my major was not computer science. i'll figure it out. all i need to know is how to get a cel's info to a variable.
|
well the 2 versions i posted should work, hey why don't you post what you're working with? perhaps i can see whats going on better.
|
| |
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
|
|
|
All times are GMT -5. The time now is 01:25 AM.
|