Re: VBA Save From Hyperlink
Hi all, I just wnated to let people know that I received a solution here: http://stackoverflow.com/quest…7/vbs-save-file-from-link
Kind Regards and thanks
Chris
Re: VBA Save From Hyperlink
Hi all, I just wnated to let people know that I received a solution here: http://stackoverflow.com/quest…7/vbs-save-file-from-link
Kind Regards and thanks
Chris
Re: VBA Save From Hyperlink
Hi, I just wondered whether someone may be able to help me please with this so that I can finish my work project.
Many thanks and kind regards
Chris
Hi, I wonder whether someone could help me please.
I've put together this code with help from an online tutorial which fetches a list files from a given folder and creates a list of these on a Excel sheet with a link against each which allows the user to open a file.
Public Sub ListFilesInFolder(SourceFolder As Scripting.folder, IncludeSubfolders As Boolean)
Dim LastRow As Long
On Error Resume Next
For Each FileItem In SourceFolder.Files
' display file properties
Cells(iRow, 3).Formula = iRow - 12
Cells(iRow, 4).Formula = FileItem.Name
Cells(iRow, 5).Select
Selection.Hyperlinks.Add Anchor:=Selection, Address:= _
FileItem.Path, TextToDisplay:="Click Here to Open"
iRow = iRow + 1 ' next row number
With ActiveSheet
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End With
For Each Cell In Range("C13:E" & LastRow) ''change range accordingly
If Cell.Row Mod 2 = 1 Then ''highlights row 2,4,6 etc|= 0 highlights 1,3,5
Cell.Interior.Color = RGB(232, 232, 232) ''color to preference
Else
Cell.Interior.Color = RGB(141, 180, 226) 'color to preference or remove
End If
Next Cell
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder, True
Next SubFolder
End If
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub
Display More
The problem I'm having is that I need to change this so that rather than opening the file, the link allows the user to save the file to a folder of their choice.
But I've been working on this for well over a week now without any success.
I've tried using the command 'Application.Dialogs(xlDialogSaveAs).Show' which I'd hoped would worked but this doesn't. I've attached a sample file which shows a list of files as the user would see this,
I just wondered whether someone could possibly look at this please and let me know where I've gone wrong.
Many thanks and kind regards
Chris
Re: VBA Open a Specific File Type
Hi MrRedli, thank you for taking the time to read my post and for coming back to me with this.
Unfortunately though, although I'm not receiving any error message this still lists all the files rather than just the .dat files.
Many thanks and kind regards
Chris
Hi, I wonder whether someone could help me please.
I'm trying to use the code below to open a specific file type, in this case '.dat'.
Sub btnFetchFiles()
Dim file As String
iRow = 7
fPath = "\\c\s\CAF2\SA\Accessibility\Dragon - Application-Specific Script Conversion 2014\Converted Scripts\Done\"
file = Dir(fPath & "*.dat")
If file <> "" Then
Set FSO = New Scripting.FileSystemObject
If FSO.FolderExists(file) <> False Then
Set SourceFolder = FSO.GetFolder(file)
IsSubFolder = True
Call ListFilesInFolder(SourceFolder, IsSubFolder)
Call ResultSorting(xlAscending, "C7")
Else
MsgBox "Selected Path Does Not Exist !!" & vbNewLine & vbNewLine & "Select Correct One and Try Again !!", vbInformation, "File Manager - http://www.LearnExcelMacro.Com"
End If
End If
End Sub
Display More
The problem I have is that although the script runs, it's showing all the file types rather than the '.dat' files I want to show.
Could someone perhaps tell me where I've gone wrong.
Many thanks and kind regards
Chris
Re: Close window Irrespective of Screen Resolution
Hi cytop, no this is fine, it will give me something to work with.
Kind regards
Chris
Re: Close window Irrespective of Screen Resolution
Hi cytop, thank you for taking the time to reply to my post and for putting the solution together which is exactly what I was after.
Many thanks and kind regards
Chris
Hi, I wonder whether someone may be able to help me please.
From the research I've carried out I've found many examples of creating a vb script using specific screen co-ordinates to find a specific point on a screen and click on this, in my case the close window button.
But could someone tell me please is it possible to construct a script which finds the 'close' button and clicks on this each time even if the screen resolution changes and hence, the screen co-ordinates have changed.
Any help would be gratefully received.
Many thanks and kind regards
Chris
Re: VBA Select Case Statement Leading To slow Script
Hi cytop, thank you very much for taking the time to send your kind message and my apologies for not applying the rules of the forum, which will ensure I comply with in future.
Many thanks and kind regards
Chris
Re: VBA Select Case Statement Leading To slow Script
Hi, thank you to those who took the time to read my post. Although I wasn't fortunate enough yo receive a reply here, I was able to do so here: http://www.excelforum.com/exce…s-on-multiple-sheets.html.
Many thanks and kind regards
Chris
Hi, I wonder whether someone may be able to help me please.
I'm using the script below to extract data from a master "All Data" sheet to multiple 'Destination' sheets, pasting the extracted data on selected rows for each of the sheets
I have to admit I've put this together from several scripts I used, and despite the fact that it works, it's incredibly slow.
'Define Constants to indicate use of OVERHEADS or PROJECTS
Const nUseAllDIR As Integer = 1
Const nUseAllEH As Integer = 2
Const nUseAllIND As Integer = 3
Const nUseAllOVH As Integer = 4
Sub ActivitiesForecasts()
' 'This is the Direct Activities routine
' 'It calls the Direct Activities, Enhancements, Indirect Activities, Overheads and Projects routine with the Indirect Activities option
Call ForecastsExtract(nUseAllDIR)
Call ForecastsExtract(nUseAllEH)
Call ForecastsExtract(nUseAllIND)
Call ForecastsExtract(nUseAllOVH)
End Sub
Sub ForecastsExtract(iOption As Integer)
Dim a
Dim ad As Worksheet
Dim bottomB As Integer
Dim dic As Object
Dim i As Long
Dim Mmonth
Dim rng As Range
Dim ws As Worksheet
Dim Y()
Application.ScreenUpdating = False
Set ad = Sheets("All Data")
bottomB = Range("B" & Rows.Count).End(xlUp).Row
For Each rng In ad.Range("B8:B" & bottomB)
If rng > 0 Then
Set ws = Sheets(rng.Value)
Application.ScreenUpdating = False
With Worksheets("All Data")
a = .Range("B8").CurrentRegion ' Load the required range in to array, named "a"
End With
Set dic = CreateObject("scripting.dictionary")
dic.comparemode = 1
With dic
For i = 2 To UBound(a) ' Loop through rows
Select Case iOption
Case nUseAllDIR
If a(i, 1) = ws.Name And InStr(a(i, 8), "TM - DIR") > 0 Then 'test if column C is "Consultancy & Requirements"
Mmonth = Trim(Format(a(i, 12), "mmm yy")) ' format the date in to mmm-yy
If Not .exists(Mmonth) Then 'If column C cells do not exist, load column E value in to dictionary using column C as item
.Item(Mmonth) = a(i, 14)
Else
.Item(Mmonth) = .Item(Mmonth) + a(i, 14) 'If column C cells do exist, then add column E in to existing item
End If
End If
Case nUseAllEH
If a(i, 1) = ws.Name And InStr(a(i, 8), "Enhancements") > 0 Then 'test if column C is "Consultancy & Requirements"
Mmonth = Trim(Format(a(i, 12), "mmm yy")) ' format the date in to mmm-yy
If Not .exists(Mmonth) Then 'If column C cells do not exist, load column E value in to dictionary using column C as item
.Item(Mmonth) = a(i, 14)
Else
.Item(Mmonth) = .Item(Mmonth) + a(i, 14) 'If column C cells do exist, then add column E in to existing item
End If
End If
Case nUseAllIND
If a(i, 1) = ws.Name And InStr(a(i, 8), "TM - IND") > 0 Then 'test if column C is "Consultancy & Requirements"
Mmonth = Trim(Format(a(i, 12), "mmm yy")) ' format the date in to mmm-yy
If Not .exists(Mmonth) Then 'If column C cells do not exist, load column E value in to dictionary using column C as item
.Item(Mmonth) = a(i, 14)
Else
.Item(Mmonth) = .Item(Mmonth) + a(i, 14) 'If column C cells do exist, then add column E in to existing item
End If
End If
Case nUseAllOVH
If a(i, 1) = ws.Name And InStr(a(i, 8), "TM - OVH") > 0 Then 'test if column C is "Consultancy & Requirements"
Mmonth = Trim(Format(a(i, 12), "mmm yy")) ' format the date in to mmm-yy
If Not .exists(Mmonth) Then 'If column C cells do not exist, load column E value in to dictionary using column C as item
.Item(Mmonth) = a(i, 14)
Else
.Item(Mmonth) = .Item(Mmonth) + a(i, 14) 'If column C cells do exist, then add column E in to existing item
End If
End If
End Select
Next
End With
With ws
a = .Range("C7", .Cells(7, .Columns.Count).End(xlToLeft)) ' Load the required range in to array, named "a"
End With
ReDim Y(1 To 2, 1 To UBound(a, 2))
With dic
For i = 1 To UBound(a, 2) ' Loop through rows
Mmonth = Trim(Format(a(1, i), "mmm yy")) ' format the date in to mmm-yy
If .exists(Mmonth) Then 'If column C cells do exist then copy the the dictionary in to match column
Y(1, i) = .Item(Mmonth)
End If
Next
End With
With ws
'Process either Direct Activities, Enhancements, Indirect Activities, Overheads or PROJECTS for resize
Select Case iOption
'Direct Activities processing resize
Case nUseAllDIR
.Range("C9").Resize(1, i - 1) = Y() 'Result-load Y in to C8
'Enhancements processing resize
Case nUseAllEH
.Range("C10").Resize(1, i - 1) = Y() 'Result-load Y in to C8
'Indirect Activities processing resize
Case nUseAllIND
.Range("C11").Resize(1, i - 1) = Y() 'Result-load Y in to C8
'Overheads processing resize
Case nUseAllOVH
.Range("C12").Resize(1, i - 1) = Y() 'Result-load Y in to C8
End Select
End With
End If
Next rng
Set dic = Nothing ' clear dic
End Sub
Display More
I've been researching 'Select Case' statements over the past few days, but all of the tutorials and examples seem very basic in comparison to what I'm trying to achieve, so I'm very unsure how I can improve this.
I just wondered whether someone could possibly look at this and offer some guidance on how I may go about correcting this problem.
Many thanks and kind regards
Chris
Re: VB Copy Selected Range & Paste In First Blank Row
I was using B as the column to reference the last used row, when it should have been column C.
Kind Regards
Chris
Re: VB Copy Selected Range & Paste In First Blank Row
Hi StephenR, thank you for taking the time to come back to me with this.
I've tried this, and after correcting an error I had made, the code works great.
All the best and kind regards
Chris
Hi, I wonder whether someone could help me please.
I'm using the code below to select a range to copy from a 'Source' sheet to the next blank row on the 'Destination' sheet.
Sub CopyRows()
Dim LastRow As Long
Dim destRng As Range
Application.ScreenUpdating = False
With Sheets("Combined")
Set destRng = .Range("B" & .Cells(.Rows.Count, "B").End(xlUp).Row + 1)
LastRow = Sheets("Monthly").Range("C" & Rows.Count).End(xlUp).Row
Sheets("Monthly").Range("B8:S" & LastRow).Copy Destination:=destRng
.Columns("B:S").AutoFit
End With
End Sub
Display More
Although the code runs without an error message being created, the data is paste at the top of the 'Destination' sheet, overwriting the existing data, instead of pasting it to the next blank row.
I've spent all day on this and read and tried multiple examples and tutorials without success.
I just wondered whether someone may be able to look at this please and let me know where I've gone wrong.
Many thanks and kind regards
Re: VBA Compare Columns & Copy Data
Hi all, thank you for taking the time to reply to my post.
I was able to obtain a solution here:http://www.excelforum.com/exce…mn-and-cell-and-copy.html
Kind regards
Chris
Hi, I wonder whether someone could help me please.
I'm using the code to compare two columns on two separate sheets, and where there is a match copy data from each row to the 'Destination' sheet.
To be more precise:
Sub AllDataSignals3()
Dim Dic As Object
Dim Dn As Range
Dim Rng As Range
'The section of code below looks in column D on the "All Resources" (Source sheet)
With Sheets("All Resources")
Set Rng = .Range(.Range("D8"), .Range("D" & Rows.Count).End(xlUp))
End With
'The section of code below then looks in column G on the 'Source' sheet and stores that value.
Set Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
For Each Dn In Rng
Set Dic(Dn & Dn.Offset(, 3)) = Dn
Next
'The section of code below then looks in column E on the "All Data" (Destination sheet)
With Sheets("All Data")
'This the column on the 'Destination' sheet you are comparing to the 'Source' sheet.
Set Rng = .Range(.Range("E8"), .Range("E" & Rows.Count).End(xlUp))
End With
'The first two lines below then searches column M on the 'Destination' sheet and stores that value.
For Each Dn In Rng
If Dic.exists(Dn & Dn.Offset(, 8)) Then
'Where the values stored in the 'Dictionary' variable match, the values from column H are copied and paste into column H on the 'Destination' sheet.
'The first offset is the 'Destination' sheet i.e. 3 columns from column E.
'The middle offset is the value being checked in column M i.e. 8 columns from column E on the Destination' sheet.
'The last offset is the 'Source' sheet i.e. 4 columns from column d.
Dn.Offset(, 3).Value = Dic.Item(Dn & Dn.Offset(, 8)).Offset(, 4).Value
End If
Next Dn
End Sub
Display More
The code works fine, but I'm having a little difficulty with making the change.
What I'd like to do is amend this section of code:
If Dic.exists(Dn & Dn.Offset(, 8)) Then
'Where the values stored in the 'Dictionary' variable match, the values from column H are copied and paste into column H on the 'Destination' sheet.
'The first offset is the 'Destination' sheet i.e. 3 columns from column E.
'The middle offset is the value being checked in column M i.e. 8 columns from column E on the Destination' sheet.
'The last offset is the 'Source' sheet i.e. 4 columns from column d.
Dn.Offset(, 3).Value = Dic.Item(Dn & Dn.Offset(, 8)).Offset(, 4).Value
End If
so that instead of using Offset(,8)), the code searches a specific cell, in this case cell B3.
I've tried making the following changes, and although the code runs, the value are not being paste into the 'Destination' sheet.
If Dic exsits((Dn.Range("B3")) then
Dn.Offset(, 3).Value = Dic.Item(Dn.Range("B3")).Offset(, 4).Value
I just wondered whether someone could possibly look at this please and let me know where I'm going wrong.
Many thanks and kind regards
Chris
Re: VBA Sum Figures Based On Row Heading
All, please don't spend any time in looking into this.
This has been solved here: http://www.excelforum.com/exce…alues-by-row-heading.html
Many thanks and kind regards
Chris
Hi, I wonder whether someone could help me please.
Using a solution from @AB33 from a post I made here: http://www.excelforum.com/exce…atch-column-headings.html, I've been able to put together a script which sums specific figures if a date field matches a column heading.
In a live environment, I've also been able to make some changes to this line,
to take account of additional filters I want to apply to the data extracted from the 'Source' to the 'Destination' sheets.
I've now come across another hurdle, which I'm afraid my knowledge, or lack of it has led me to hear.
What I'm trying to achieve is as follows:
I just wondered whether someone could possibly look at this please and offer some guidance on how I may achieve this.
I appreciate that my description may not be the most straight forward, so I have placed a file here: https://www.dropbox.com/s/k6ox…%20Categories%20Test2.xls
Re: VBA Count Unique Values
Hi Kenneth Hobson, thank you for taking the time to reply to my post.
Unfortunately I'm unable to post the file because of it's confidential content, but if you say that the logic is correct, I'll have a look at this again to make sure the logic matches the requirements.
Thank you also for the tip.
All the best and kind regards