call .bas to read a cell and write in another two.

Post Reply
User avatar
Princy557
Posts: 192
Joined: Wed May 18, 2011 10:32 am

call .bas to read a cell and write in another two.

Post by Princy557 »

HI
Using basic maker, how do I open a worksheet and read two numbers from particular two cells.
Then write back to those cells new information?

I hope to run it from a planmaker button.

Regards Princy557 :)
Regards

Princy557
User avatar
Princy557
Posts: 192
Joined: Wed May 18, 2011 10:32 am

Re: call .bas to read a cell and write in another two.

Post by Princy557 »

Hi
Getting nowhere on this....

How do I pass a value (based on a cell value) to BasicMaker code and return another back to planmaker.
Regards

Princy557
elmonopascual
Posts: 12
Joined: Sat Aug 31, 2019 6:25 pm

Re: call .bas to read a cell and write in another two.

Post by elmonopascual »

Hi Princy557. The following example reads the value of two cells in the active sheet of the active workbook, and then writes new values in them:

Code: Select all

Dim pm as Object
Set pm = CreateObject("PlanMaker.Application")
pm.Application.Visible = True

Dim cell1, cell2 as String

'Read the value of A1 and A2 cells:
Set cell1 = pm.Application.Range("A1").Value
Set cell2 = pm.Application.Range("A2").Value

MsgBox(cell1 + " - " + cell2)

'Write new values in A1 and A2 cells:
pm.Application.Range("A1").Value = 10
pm.Application.Range("A2").Value = 20

Set pm = Nothing
User avatar
Princy557
Posts: 192
Joined: Wed May 18, 2011 10:32 am

Re: call .bas to read a cell and write in another two.

Post by Princy557 »

Hi,
Sorry for delay, got caught up in family stuff.
Thanks for the reply I'll try it this evening and hopefully learn something as well.
Cheers for you help.
Regards

Princy557
User avatar
Princy557
Posts: 192
Joined: Wed May 18, 2011 10:32 am

Re: call .bas to read a cell and write in another two.

Post by Princy557 »

Hi again
Can I be cheeky and ask how that would work with a date?
How do I read a date and put say todays date back into another cell?
Regards

Princy557
User avatar
Princy557
Posts: 192
Joined: Wed May 18, 2011 10:32 am

Re: call .bas to read a cell and write in another two.

Post by Princy557 »

Hi again
Can I be cheeky and ask how that would work with a date?
How do I read a date and put say todays date back into another cell?
Regards

Princy557
elmonopascual
Posts: 12
Joined: Sat Aug 31, 2019 6:25 pm

Re: call .bas to read a cell and write in another two.

Post by elmonopascual »

Hi Princy557.
The next example opens a file (Invoices.xlsx) and writes the current date in column A, and a secuential number in column B, in the next free row.
The file needs to have the current date in cell D1 [ =Today() ]. The code reads that date and then writes it on column A.
I've tried to use the Date() function but I get an error: Type mismatch (maybe this is a bug?)

To test the example, create the file Invoices.xlsx with the current date in cell D1 and save it. Open the Basic Maker Editor and paste the code, change the path to the actual path of your file, and then run it.

Code: Select all

Dim pm as Object
Set pm = CreateObject("PlanMaker.Application")
pm.Application.Visible = True

pm.Workbooks.Open("\Users\User\Desktop\Invoices.xlsx")

Dim today as Variant
today = pm.Application.Range("D1").Value 'D1 = Today()

For n = 1 to 1048576
	If pm.Application.Range("B" & n).Value = "" Then
		If n > 1 Then
			pm.Application.Range("B" & n).Value = pm.Application.Range("B" & (n - 1)).Value + 1
		Else
			pm.Application.Range("B" & n).Value = 1
		End If

		'pm.Application.Range("A" & n).Value = Date() 'Type mismatch: Is this a bug?
		pm.Application.Range("A" & n).Value = today

		Exit For
	End If
Next n
User avatar
Princy557
Posts: 192
Joined: Wed May 18, 2011 10:32 am

Re: call .bas to read a cell and write in another two.

Post by Princy557 »

Hi elmonopascual,
Thank you for that it works a treat, obviously I had to modify it slightly for my personal use. But it is really useful to me. Thanks again. :D
Regards

Princy557
User avatar
Princy557
Posts: 192
Joined: Wed May 18, 2011 10:32 am

Re: call .bas to read a cell and write in another two.

Post by Princy557 »

Hi,
Can I ask one more thing on this very educational thread...

I have a 'BlankInvoice' worksheet. How do I copy it in its entirety
How do I copy it to the right (of the BlankInvoice), with the new invoice number just created prior in this thread.

I'm finding things difficult to follow in the .pdf destcriptions, could do with more examples.

I have a feeling that there are a few watchers also finding this very useful, Thankyou.
:D :)
Regards

Princy557
Post Reply

Return to “BasicMaker 2018 for Windows”